home *** CD-ROM | disk | FTP | other *** search
/ World of Education / World of Education.iso / world_p / pcshx10b.zip / PCSHX10B.EXE / GNUFGREP.EXE / GREPDOCS.EXE / GETWD.C < prev    next >
C/C++ Source or Header  |  1990-08-12  |  2KB  |  80 lines

  1. /*-
  2.  * MSDOS routine for getting the working directory on a specified drive.
  3.  * By Barry Schwartz, 12 August 1990
  4.  */
  5.  
  6. #include <stddef.h>
  7. #include <dos.h>
  8.  
  9.  
  10. #undef LARGE_DATA
  11. #if defined(M_I86CM) || defined(M_I86LM) || defined(M_I86HM)
  12. #define LARGE_DATA
  13. #endif
  14.  
  15.  
  16. static union REGS inregs, outregs;
  17. #ifdef LARGE_DATA
  18. static struct SREGS segregs;
  19. #endif
  20.  
  21.  
  22.  
  23. /*
  24.  * get_working_directory(buf, drive) Returns buf, or NULL if the drive
  25.  * specification is invalid. 
  26.  */
  27.  
  28. char           *
  29. get_working_directory(buf, drive)
  30. char           *buf;        /* Pointer to a buffer of sufficient size
  31.                  * (_MAX_DIR) */
  32. int             drive;        /* Drive number (0=default, 1=`A:',
  33.                  * 2=`B:', etc.) */
  34. {
  35.     inregs.h.ah = 0x47;        /* DOS interrupt number */
  36.     inregs.h.dl = drive;
  37. #ifdef LARGE_DATA
  38.     inregs.x.si = FP_OFF(buf);    /* SI points to buf within the segment */
  39.     segregs.ds = FP_SEG(buf);    /* DS points to the segment */
  40.     intdosx(&inregs, &outregs, &segregs);
  41. #else
  42.     inregs.x.si = (unsigned int) buf;
  43.     intdos(&inregs, &outregs);
  44. #endif
  45.     if (outregs.x.cflag)
  46.     return NULL;
  47.     return buf;
  48. }
  49.  
  50.  
  51.  
  52. #ifdef TEST
  53.  
  54.  
  55. #include <stdlib.h>
  56.  
  57.  
  58. char            working_dir[_MAX_PATH];
  59.  
  60.  
  61. main()
  62. {
  63.     int             drive;
  64.     char           *result;
  65.  
  66.     for (drive = 0; drive != 10; ++drive)
  67.     {
  68.     result = get_working_directory(working_dir, drive);
  69.     if (result)
  70.         printf("drive = %2d        working directory = %s\n",
  71.            drive, result);
  72.     else
  73.         printf("drive = %2d        invalid drive specification\n",
  74.            drive);
  75.     }
  76. }
  77.  
  78.  
  79. #endif
  80.